package leetcodev1.树;

import java.util.ArrayList;
import java.util.List;

public class LeetCode144 {

    public List<Integer> preorderTraversal(TreeNode root) {
        List<Integer> ret = new ArrayList<>();
        dfs(ret, root);
        return ret;
    }

    private void dfs(List<Integer> ret, TreeNode root) {
        if (root == null) {
            return;
        }

        ret.add(root.val);
        dfs(ret, root.left);
        dfs(ret, root.right);
    }
}
